﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Windows;
using System.Windows.Input;
using System.Windows.Controls.Primitives;

namespace Kokomo.Controls
{
	public class DiagramControl : Selector
	{
		static DiagramControl()
		{
			DefaultStyleKeyProperty.OverrideMetadata(typeof(DiagramControl), new FrameworkPropertyMetadata(typeof(DiagramControl)));
			FocusableProperty.OverrideMetadata(typeof(DiagramControl), new FrameworkPropertyMetadata(false));
			FocusManager.IsFocusScopeProperty.OverrideMetadata(typeof(DiagramControl), new FrameworkPropertyMetadata(true));
		}
		protected override System.Windows.DependencyObject GetContainerForItemOverride()
		{
			DiagramItem item = new DiagramItem();
			return item;
		}
		protected override bool IsItemItsOwnContainerOverride(object item)
		{
			return (item is DiagramItem);
		}

		protected override void OnSelectionChanged(SelectionChangedEventArgs e)
		{
			base.OnSelectionChanged(e);

			if (e.AddedItems.Count > 0)
			{
				object item = e.AddedItems[0];
				FrameworkElement element = this.ItemContainerGenerator.ContainerFromItem(item) as FrameworkElement;
				if (element != null)
				{
					element.Focus();
					element.BringIntoView();
				}
			}
		}
	}
}
